#pragma once
#ifndef EDITOR__RENDER__WIDGET__INCLUDED__HH
#define EDITOR__RENDER__WIDGET__INCLUDED__HH

#include "LitEditorPrerequisites.h"
#include <LitMeshDescriptionManager.h>
#include <Ogre.h>
#include <QtGui>
#include <qwidget.h>

#ifdef Q_WS_X11
  #include <QtGui/QX11Info>
#endif

namespace Lit
{
	namespace Editor
	{
		class LIT_API RenderWidgetListener;
		class LIT_API _OgreWidget : public QWidget
		{
			Q_OBJECT
			std::vector<RenderWidgetListener*> mListeners;
		public:
			_OgreWidget(QWidget *parent = NULL );
			virtual ~_OgreWidget();
	
			Ogre::Root         *ogreRoot() const{ return mogreRoot; }
			Ogre::SceneManager *ogreSceneManager() const{ return mogreSceneManager; }
			Ogre::RenderWindow *ogreRenderWindow() const{ return mogreRenderWindow; }
			Ogre::Viewport     *ogreViewport() const{ return mogreViewport; }
			Ogre::Camera       *ogreCamera() const{ return mogreCamera; }
			
			void addListener( RenderWidgetListener * listener );
			void removeListener( RenderWidgetListener * listener );
			bool hasListener( RenderWidgetListener * lstnr ) const;

		public slots:
			void setBackgroundColor(QColor c);

		signals:
			void ogreInitialise( );
			void ogreShutdown();

		protected:
			void mousePressEvent( QMouseEvent*evt );
			void mouseReleaseEvent( QMouseEvent*evt );
			void mouseMoveEvent( QMouseEvent*evt );

			void wheelEvent(QWheelEvent* evt);

			virtual void moveEvent(QMoveEvent *e);
			virtual QPaintEngine* paintEngine() const;
			virtual void paintEvent(QPaintEvent *e);
			virtual void resizeEvent(QResizeEvent *e);
			virtual void showEvent(QShowEvent *e);

		private:
			void initOgreSystem();
 
		private:
			Ogre::Root         *		mogreRoot;
			Ogre::SceneManager *		mogreSceneManager;
			Ogre::RenderWindow *		mogreRenderWindow;
			Ogre::Viewport     *		mogreViewport;
			Ogre::Camera       *		mogreCamera;
 
		};

		class LIT_API RenderWidgetListener : public Ogre::FrameListener
		{
		public:
			RenderWidgetListener(){}
			virtual ~RenderWidgetListener(){}

			virtual bool frameStarted( const Ogre::FrameEvent &evt ){ return true; }

			virtual void mousePressed(const QPoint& pos, Qt::MouseButtons){}
			virtual void mouseMoved(const QPoint& pos, Qt::MouseButtons){}
			virtual void mouseReleased(const QPoint& pos, Qt::MouseButtons){}

			virtual void mouseScrolled( int delta ){}
			
			virtual void createScene(){}
			virtual void destroyScene(){}
		};
		class LIT_API RenderWidget :
			public _OgreWidget
		{
		public:
			RenderWidget(QWidget*parent);
			~RenderWidget(void);
		};
	};
};
#endif